use std::io;
use rand::Rng; // trait
use std::cmp::Ordering;

fn main() {
    println!("猜数！");

    loop {

        println!("猜测第一个数！");

        let mut guess = String::new();

        let secret_number = rand::thread_rng().gen_range(1..100);

        io::stdin().read_line(&mut guess).expect("无法执行！");

        println!("猜测第一个数！{}", secret_number);

        // shadow  到这里隐藏属性类型
        let guess:u32 = match guess.trim().parse() {
            Ok(num) => num,
            Err(_) => continue,
        };

        match guess.cmp(&secret_number) {
            Ordering::Equal => println!("You win!"),
            Ordering::Less => println!("To small!"),
            Ordering::Greater => {
                println!("To big!");
                break;
            }
        }
    }
    
}
